<template>
	<div>
		<!-- :visible.sync="$store.state.mealflag" -->
		<el-dialog :close-on-click-modal="flag" :show-close="flag" title="套餐信息" :visible.sync="$store.state.mealflag" width="30%"
		 center>
			<span>
				<!-- ////////////////////// -->
				<el-form ref="form" label-width="80px">
					<el-form-item label="套餐名称">
						<el-input v-model="mealInfo.mealname" maxlength=15></el-input>
					</el-form-item>
					<el-form-item label="套餐时间">
						<el-input v-model="mealInfo.mealtime" maxlength=5 @keyup.native="trim1()" style="width:40%"></el-input> 天
					</el-form-item>
					<el-form-item label="套餐价格">
						<el-input v-model="mealInfo.mealmoney" maxlength=15 @keyup.native="trim()" style="width:40%"></el-input> 元
					</el-form-item>
					<el-form-item label="是否启用">
						<el-switch v-model="mealInfo.mealstate"></el-switch>
					</el-form-item>
					<!-- 		  <el-form-item label="活动性质">
		    <el-checkbox-group v-model="mealInfo.mealtype">
		      <el-checkbox label="长期套餐" name=1></el-checkbox>
		      <el-checkbox label="短期套餐" name=2></el-checkbox>
		    </el-checkbox-group>
		  </el-form-item> -->
					<el-form-item label="活动性质">
						<el-radio v-model="mealInfo.mealtype" :label="lab1">长期套餐</el-radio>
						<el-radio v-model="mealInfo.mealtype" :label="lab2">短期套餐</el-radio>
					</el-form-item>
					<el-form-item label="套餐内容">
						<el-input type="textarea" v-model="mealInfo.mealmsg" maxlength=55></el-input>
					</el-form-item>
				</el-form>
				<!-- ////////////////////// -->
			</span>
			<span slot="footer" class="dialog-footer">
				<el-button type="danger" @click="mealflag1(false)">删除</el-button>
				<el-button @click="mealflagcancel()">取 消</el-button>
				<el-button type="primary" @click="mealflag(false)">保存</el-button>
			</span>
		</el-dialog>
	</div>
</template>

<script>
	import {
		request
	} from "network/request.js"
	export default {
		props: {
			mealInfo: {
				mealid: '2',
				mealname: '2',
				mealmsg: '3',
				mealtype: '4',
				mealstate: '5',
				mealmoney: '6',
				mealtime: '7',
				mealremark: '8',
			}
		},
		data() {
			return {
				lab1: 1,
				lab2: 2,
				flag: false,
				flag2: true,
				mealstate2:"1"
			};
		},
		methods: {
			mealflag(flag) {
				if(this.mealInfo.mealstate==true){
					this.mealstate2="1";
				}else{
				this.mealstate2="0"
				}
				request({
					url: '/Meal/Meals',
					method: 'patch',
					data: {
						// id:this.$store.state.mealid
							"mealid": this.mealInfo.mealid,
							"mealmoney":this.mealInfo.mealmoney,
							"mealmsg": this.mealInfo.mealmsg,
							"mealname": this.mealInfo.mealname,
							"mealremark": "string",
							"mealstate": this.mealstate2,
							"mealtime": this.mealInfo.mealtime,
							"mealtype":this.mealInfo.mealtype
					}
				}).then(res => {
					console.log(this.mealstate2)
					this.$store.commit("updateMeal", false)
					this.$store.commit("updateMealid", 0)
					this.$router.push("blank_emt")
				})
			},
			mealflag1(flag) {
				/*提醒用户是否删除*/
				     this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
				          confirmButtonText: '确定',
				          cancelButtonText: '取消',
				          type: 'warning'
				        }).then(() => {
									/*****************/
									if(this.mealInfo.mealstate==true){
										this.mealstate2="1";
									}else{
									this.mealstate2="0"
									}
									request({
										url: '/Meal/Meals',
										method: 'patch',
										data: {
											// id:this.$store.state.mealid
												"mealid": this.mealInfo.mealid,
												"mealmoney":this.mealInfo.mealmoney,
												"mealmsg": this.mealInfo.mealmsg,
												"mealname": this.mealInfo.mealname,
												"mealremark": "string",
												"mealstate": 2,
												"mealtime": this.mealInfo.mealtime,
												"mealtype":this.mealInfo.mealtype
										}
									}).then(res => {
										console.log(this.mealstate2)
										this.$store.commit("updateMeal", false)
										this.$store.commit("updateMealid", 0)
										this.$router.push("blank_emt")
									})
									
									/*****************/
				          this.$message({
				            type: 'success',
				            message: '删除成功!'
				          });
				        }).catch(() => {
				          this.$message({
				            type: 'info',
				            message: '已取消删除'
				          });          
				        });
				
				
				
				/*************************/
			
			},
			mealflagcancel() {
				this.$store.commit("updateMeal", false)
				this.$store.commit("updateMealid", 0)
			},
			onSubmit() {
				console.log('submit!');
			},
			trim() {
				this.mealInfo.mealmoney = this.mealInfo.mealmoney.replace(/[^0-9\.]/g, '')
				// console.log(this.form.name)
			},
			trim1() {
				this.mealInfo.mealtime = this.mealInfo.mealtime.replace(/[^0-9]/g, '')
				// console.log(this.form.name)
			}
		}
	};
</script>

<style>
</style>
